#!/usr/bin/python3
# @Time    : 2018/6/3 上午 7:35:47  
# @Author  : LaoJI

import datetime
from sqlalchemy import Column, ForeignKey, func
from sqlalchemy import String, Unicode, DateTime, Boolean
from sqlalchemy import SmallInteger, Integer, TIMESTAMP
from sqlalchemy.orm import relationship
from app.models.base import db, Base


class Exam_Score(Base):
    __tablename__ = 'exam_scores'
    id = Column("id", Integer, primary_key=True)
    time = Column("time", Integer, nullable=False)
    score = Column("score", Integer, nullable=False)
    sid = Column(Integer, ForeignKey('students.student_id'), nullable=False)
    eid = Column(Integer, ForeignKey('exams.exam_id'), nullable=False)
    user = relationship('User', backref=db.backref('es', lazy='dynamic'))
    exam = relationship('Exam', backref=db.backref('es', lazy='dynamic'))

    @staticmethod
    def addExamScore(uid, examid, time, rightans):
        es = Exam_Score()
        es.time = time
        es.eid = examid
        es.sid = uid
        es.score = rightans
        db.session.add(es)
        db.session.commit()
